package coroutine

import (
	"fmt"
	"time"
)

// ChannelCoroutine 使用channel通道
func ChannelCoroutine() {
	fmt.Println("The main thread starts running......")
	startTime := time.Now()
	ch1 := make(chan int)
	ch2 := make(chan string)
	go func(ch chan int) {
		time.Sleep(2 * time.Second)
		result := 99999
		ch <- result
	}(ch1)
	go func(ch chan string) {
		time.Sleep(2 * time.Second)
		result := "hello channel!"
		ch <- result
	}(ch2)
	msg := <-ch1
	close(ch1)
	msg1 := <-ch2
	close(ch2)
	fmt.Println(msg)
	fmt.Println(msg1)
	fmt.Println("program perform times:", time.Since(startTime))
}

// Activity 活动管理的方法
type Activity interface {
	Lottery(userId int)
}
